package com.dkm.ec.stock.repository.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.repository.AbstractRepository;
import com.dkm.ec.stock.domain.Stock;
import com.dkm.ec.stock.repository.StockRepository;
import com.dkm.ec.stock.persistence.dao.StockQueryDao;
import com.dkm.ec.stock.persistence.entity.StockPo;

/**
 * 对象功能:库存表 Repository接口的实现类
 * 开发公司:dkm.com
 * 开发人员:ZHH
 * 创建时间:2017-05-22 18:48:08
 */
@Repository
public class StockRepositoryImpl extends AbstractRepository<String, StockPo,Stock> implements StockRepository{
	  
	@Resource
	private  StockQueryDao stockQueryDao;

	public Stock newInstance() {
		StockPo po = new StockPo();
		Stock stock = SpringHelper.getBean(Stock.class);
		stock.setData(po);
		return stock;
	}

	public Stock newInstance(StockPo po) {
		Stock stock = SpringHelper.getBean(Stock.class);
		stock.setData(po);
		return stock;
	} 
	
	@Override
	protected IQueryDao<String, StockPo> getQueryDao() {
		
		return stockQueryDao;
	}

	@Override
	public StockPo findBySkuId(String skuId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("whereSql", "sku_id_='"+skuId+"'");
		List<StockPo> stockPos =   stockQueryDao.findAll(params);
		if(stockPos.size() > 0){
			return  stockPos.get(0);
		}
		return null;
	}
	
}
